package ExamSystemClient.managerSystem.ExamManagement;

import ExamSystemClient.client.ClientScanner;
import ExamSystemClient.model.ChoiceQuestion;
import ExamSystemClient.model.Option;

import java.util.List;

/**
 * 修改信息
 *
 * @author huangshuxian
 */
public class ModifyQuestion extends QuestionManage {

    public ModifyQuestion(List<ChoiceQuestion> questions) {
        super(questions);
    }

    @Override
    public void operate() {
        //1、提示用户输入需要修改的题号
        System.out.println("请输入需要修改的考题题号：");
        int index = getIndexByNumber(ClientScanner.getScanner().nextInt());
        if (index >= 0){
            //2、提示用户输入需要修改的信息
            ChoiceQuestion question = questions.get(index);
            System.out.println("请输入需要修改的信息编号(1题干/2选项A/3选项B/4选项C/5选项D/6正确选项)：");
            int modifyInfoName = ClientScanner.getScanner().nextInt();
            System.out.println("请输入需要新的的信息内容：");
            String value = ClientScanner.getScanner().next();
            switch(modifyInfoName){
                case 1:
                    question.setStem(value);
                    break;
                case 2:
                    question.setOptionA(new Option(Option.OptionCode.OPTION_A,value));
                    break;
                case 3:
                    question.setOptionB(new Option(Option.OptionCode.OPTION_B,value));
                    break;
                case 4:
                    question.setOptionC(new Option(Option.OptionCode.OPTION_C,value));
                    break;
                case 5:
                    question.setOptionD(new Option(Option.OptionCode.OPTION_D,value));
                    break;
                case 6:
                    question.setRightOption(Option.OptionCode.parse(value));
                    break;
                    default:
            }
            System.out.println("修改考题成功！");
            System.out.println("修改后的考题为：" + question);
        }else{
            System.out.println("输入的考题编号找不到匹配的数据！");
        }


    }

    @Override
    public ModifyQuestion show() {
        System.out.println("修改考题信息！");
        return this;
    }
}
